package org.builder.main;

import org.annotation.ExcelColumn;
import org.builder.excel.BaseExcelExportBuild;
import org.builder.excel.ExcelDirector;
import org.builder.excel.NormalExcelImp;
import org.pojo.TimeSegmentCustomerFlowAnalysisBean;
import org.util.MethodUtils;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author huangshen
 * @version 0
 * @description ExcelTest
 * @since 2022/1/30 21:35
 */
public class ExcelTest {

    public static void main(String[] args) throws Exception{

        List<TimeSegmentCustomerFlowAnalysisBean> beanList = new ArrayList<>();
        Class<TimeSegmentCustomerFlowAnalysisBean> targetClass = TimeSegmentCustomerFlowAnalysisBean.class;

        List<Method> methodList = new MethodUtils(targetClass).getSetMethodListByAnnotation(ExcelColumn.class);
        int i = 1000;
        TimeSegmentCustomerFlowAnalysisBean bean = new TimeSegmentCustomerFlowAnalysisBean();
        while (i > 0) {
            TimeSegmentCustomerFlowAnalysisBean clone = (TimeSegmentCustomerFlowAnalysisBean) bean.clone();
            for (Method method : methodList) {
                method.invoke(clone, "1");
            }
            i--;
            beanList.add(clone);
        }


//        int i = 300000;
//        List<ExcelTestBean> beanList = new ArrayList<>();
//        while (i > 0) {
//            beanList.add(new ExcelTestBean(1, 2, 3));
//            i--;
//        }

//        Class<ExcelTestBean> targetClass = ExcelTestBean.class;

        // 普通Excel导出
        String exportPath = "C:/Users/gugu/Desktop/test1/" +new Random().nextInt() + ".xls";
        long start1 = System.currentTimeMillis();
        ExcelDirector director = new ExcelDirector(new NormalExcelImp());
        BaseExcelExportBuild normalExcel = director.createNormalExcel(exportPath, targetClass, beanList);
        normalExcel.createExcel();
        long end1 = System.currentTimeMillis();

        System.out.println("method one use time:" + (end1 - start1));


//        long start2 = System.currentTimeMillis();
//        ExcelDirector director2 = new ExcelDirector(new NormalFastExcelImp());
//        BaseExcelExportBuild normalExcel2 = director2.createNormalExcel(exportPath, targetClass, beanList);
//        normalExcel2.createExcel();
//        long end2 = System.currentTimeMillis();
//
//        System.out.println("method two use time:" + (end2 - start2));

        // 2323 2379 2486


    }
}
